import java.util.Random;
import java.util.Scanner;

/**
 * 使用方法，重写抽奖系统
 */
public class Demo05 {

    static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {

        start();
    }

    public static void start(){
        System.out.println(
                        "           1. 登陆\n" +
                        "           2. 注册\n" +
                        "           3. 退出\n" +
                        "        请选择：");

        String choose = scanner.next();

        switch (choose){
            case "1":
                //登录
                login();
                break;
            case "2":
                //注册
                register();
                break;
            case "3":
                //退出
                exit();
                break;
        }
    }

    public static void login(){
        int random = new Random().nextInt(9000)+1000;
        System.out.println("验证码为："+random);

        System.out.println("请输入用户名：");
        String username = scanner.next();

        System.out.println("请输入密码：");
        String password = scanner.next();

        System.out.println("请输入验证码：");
        String randomStr = scanner.next();

        if("admin".equals(username) && "123456".equals(password) && randomStr.equals(random+"")) {
            System.out.println("登录成功！");

            menu();
        }
    }

    public static void register(){

    }

    public static void exit(){

    }

    /**
     * 主菜单
     */
    public static void menu(){
        System.out.println(
                        "            >>主菜单\n" +
                        "           1. 幸运抽奖\n" +
                        "           2. 购物结算\n" +
                        "           3. 退出系统");

        String choose = scanner.next();
        switch (choose){
            case "1":
                //幸运抽奖
                luck();
                break;
            case "2":
                //购物结算
                shop();
                break;
            case "3":
                exit();
        }
    }

    public static void luck(){
        System.out.println("请输入4个数的账户：");
        int num = scanner.nextInt();

        //获取到了百位数
        int h = num % 1000 / 100;

        int r = new Random().nextInt(10);

        if(h == r){
            System.out.println("恭喜你，中奖了，获得MP3一个");
        }else{
            System.out.println("随机产生的幸运数为："+r+"，很遗憾，下次吧");

        }
    }

    public static void shop(){
        //实现
    }
}
